<template>
  <div class="icons">
    <swiper class="swiper-wrapper" :options="swiperOption">
      <swiper-slide v-for="(item,index) in pages" :key="index">
        <div class="icon" v-for="li in item" :key="li.id">
          <div class="icon-img">
            <img :src="li.imgUrl" class="icon-img-content">
          </div>
          <p class="icon-desc" v-text="li.desc"></p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    iconList: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import "~styles/varibles.styl"
  .icons
    margin-top: .1rem
    .swiper-wrapper
      overflow: hidden
      height: 0
      padding-bottom: 50%
      .icon
        overflow: hidden
        position: relative
        float: left
        width: 25%
        height: 0
        padding-bottom: 25%
        .icon-img
          position: absolute
          left: 0
          top: 0
          right: 0
          bottom: .44rem
          .icon-img-content
            display: block
            margin: 0 auto
            -webkit-box-sizing: border-box
            -moz-box-sizing: border-box
            box-sizing: border-box
            height: 100%
            padding: .1rem
        .icon-desc
          position: absolute
          right: 0
          bottom: 0
          height: .44rem
          left: 0
          line-height: .44rem
          text-align: center
          color: $darkTextColor
          ellipsis()
</style>
